package com.wr.recruit.service.service.impl;

import com.wr.recruit.service.dao.dbo.RoleDbo;
import com.wr.recruit.service.dao.repo.RoleRepo;
import com.wr.recruit.service.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;

import java.util.ArrayList;
import java.util.List;

import static com.wr.recruit.service.utils.Constants.*;

@Service
public class RoleServiceImpl implements RoleService {

    private RoleRepo roleRepo;

    @Autowired
    public RoleServiceImpl(RoleRepo roleRepo) {
        this.roleRepo = roleRepo;
    }

    @Override
    public RoleDbo getRoleByRoleName(String roleName) {
        return roleRepo.findAllByRoleName(roleName);
    }

    @PostConstruct
    private void initRole(){
        List<RoleDbo> list = new ArrayList<>();
        RoleDbo admin = new RoleDbo(1, ADMIN,"系统管理员","系统管理员");
        list.add(admin);
        RoleDbo investigator = new RoleDbo(2, INVESTIGATOR,"hr","招聘人员，管理人员架构");
        list.add(investigator);
        RoleDbo interviewer = new RoleDbo(3, INTERVIEWER,"面试官","面试");
        list.add(interviewer);
        RoleDbo applicant = new RoleDbo(4, APPLICANT,"申请人","请求面试者");
        list.add(applicant);
        RoleDbo employee = new RoleDbo(5, EMPLOYEE,"员工","通过招聘进入公司的员工");
        list.add(employee);
        roleRepo.save(list);
    }
}
